package model

import (
	"time"

	"github.com/jinzhu/gorm"
	uuid "github.com/satori/go.uuid"
)

type File struct {
	ID        uuid.UUID `gorm:"type:char(36); primaryKey"`
	CreatedAt time.Time `gorm:"type:timestamp"`
	UpdatedAt time.Time `gorm:"type:timestamp"`
	UserID    uint      `gorm:"not null"`
	Name      string    `gorm:"type:varchar(50); not null"`
	Content   string    `gorm:"type:text"`
}

// This functions are called before creating any file
func (file *File) BeforeCreate(scope *gorm.Scope) error {
	return scope.SetColumn("ID", uuid.NewV4())
}
